<?php

/**
 * @file This shall do all the interaction with the entity table.
 */

class entity {
  public $eid;
  public $created_at;
  public $definition_id;
  public $path;
  
  public static function get($eid = NULL) {
 	$query = 'SELECT e.`eid`, e.`created_at`, e.`path`, e.`definition_id` ';
    $query .= 'FROM `ENTITIES` e ';
	$args = $eid;
	if($eid && is_numeric($eid) && is_int($eid+0)) {
	  $query .= 'WHERE eid=?';
	} else {
	  $query .= 'ORDER BY e.`created_at` DESC';
	  $query .= 'LIMIT 0,1';
	}
	$object = new entity();
	$statement = database_execute($query, $args);
	$statement->bind_return($object->eid, $object->created_at, $object->definition_id, $object->path);
	$statement->fetch();
	$statement->close();
	return $object;
  }
  public static function getAll($order_by = 'created_at', $sequence = 'DESC') {
  	$query = 'SELECT e.`eid`, e.`created_at`, e.`path`, e.`definition_id` ';
    $query .= 'FROM `ENTITIES` e ';
	$query .= 'ORDER BY ? ?';
	
	
  }
  public static function insert() {
  	
  }
  public static function update() {
  	
  }
}
